package com.baizhi.cmfz.service.impl;

import com.baizhi.cmfz.dao.LogDao;
import com.baizhi.cmfz.entity.Log;
import com.baizhi.cmfz.service.LogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LogServiceImpl implements LogService {
    @Autowired(required = false)
    private LogDao logDao;
    private Logger logger = LoggerFactory.getLogger(LogServiceImpl.class);
    @Override
    @Transactional
    public Map selectLog(String logContent, String logType, int page, int limit) {
        //做数据处理
        int offset = (page -1)*limit;
        if (logContent != null && !logContent.equals("")) {
            //模糊搜索拼接
            logContent = "%"+logContent+"%";
        }else {
            logContent = null;
        }
        if (logType == null || logType.equals("")) {
            logType = null;
        }
        //日志输出收到的参数
        logger.debug("日志内容搜索收参"+logContent);
        logger.debug("日志类型搜索收参"+logType);
        //查询出满足条件的数据
        List<Log> logs = logDao.selectLog(logContent,logType,offset,limit);
        //查询出满足条件的总条数
        int count = logDao.selectLogCount(logContent,logType);
        Map map = new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("data",logs);
        map.put("count",count);
        return map;
    }

    @Override
    @Transactional
    public List<String> selectType() {
        return logDao.selectType();
    }
}
